home *** CD-ROM | disk | FTP | other *** search
- // phong_vertex.cg
- //
- // This file cannot be directly compiled through CG... it first must be
- // parsed to insert channel-specific instructions.
- //
-
- struct vert2frag
- {
- float4 hPosition : POSITION;
-
- #if defined(BUMP_MAP)
- float3 wBinormal : TEXCOORD0;
- float3 wTangent : TEXCOORD1;
- float4 bumpTexUv : TEXCOORD2;
- #else
- float3 wNormal : TEXCOORD0;
- #endif // BUMP_MAP
-
- float4 transpTexUv : TEXCOORD3;
- float4 incanTexUv : TEXCOORD4;
- float4 reflectivityTexUv : TEXCOORD5;
- float4 wPosition : TEXCOORD6;
- };
-
- // define inputs from application
- struct app2vert
- {
- float4 position : POSITION;
- float4 normal : NORMAL;
-
- #ifdef BUMP_MAP
- float4 tangent : TEXCOORD0;
- float4 bumpTexUv : TEXCOORD1;
- #endif // BUMP_MAP
-
- float4 transpTexUv : TEXCOORD2;
- float4 incanTexUv : TEXCOORD3;
- float4 reflectivityTexUv : TEXCOORD4;
- };
-
- vert2frag main(app2vert IN,
- uniform float4x4 modelViewProj,
- uniform float4x4 objToWorldMatrix,
- uniform float4x4 objToWorldMatrix_invtrans)
- {
- vert2frag OUT;
-
- modelViewProj = glstate.matrix.mvp;
-
- // Compute the clip-space vertex position.
- //
- OUT.hPosition = mul(modelViewProj, IN.position);
-
- // Compute the world-space vertex position.
- //
- OUT.wPosition = mul(objToWorldMatrix, IN.position);
-
- // Copy the texture coordinates.
- //
- OUT.transpTexUv = IN.transpTexUv;
- OUT.incanTexUv = IN.incanTexUv;
- OUT.reflectivityTexUv = IN.reflectivityTexUv;
-
- // Compute the geometric normal, expressed in world space.
- // Note: we pass in the tangent and binormal vector
- // rather than the normal. Then in the fragment program,
- // we recompute the normal using a cross-product. This ensures
- // that we'll get the correct normal even when the model matrix
- // has non-proportional scale, and it's cheaper than multiplying
- // by the inverse-transpose.
- //
- #ifdef BUMP_MAP
- float3 oNormal = normalize(IN.normal.xyz);
- float3 oBinormal = normalize(cross(oNormal, IN.tangent.xyz));
- float3 oTangent = cross(oBinormal, oNormal);
-
- float3 wTangent = mul(objToWorldMatrix_invtrans, float4(oTangent, 0)).xyz;
- OUT.wTangent = normalize(wTangent);
-
- float3 wBinormal = mul(objToWorldMatrix_invtrans, float4(oBinormal, 0)).xyz;
- OUT.wBinormal = normalize(wBinormal);
-
- OUT.bumpTexUv = IN.bumpTexUv;
- #else
- float4 oNormal = float4(normalize(IN.normal.xyz), 0);
- OUT.wNormal = mul(objToWorldMatrix_invtrans, oNormal).xyz;
- #endif // BUMP_MAP
-
- return OUT;
- }
-